package org.chronologger.poppaea.client.utils;

import java.util.Date;

import com.google.gwt.dom.client.Document;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;

public class Logger {

	private final static FlowPanel messages = new FlowPanel();
	
	static {
		FlowPanel containerPanel = new FlowPanel();
		containerPanel.setStyleName("logger-panel");
		containerPanel.add(messages);
		Document.get().getBody().appendChild(containerPanel.getElement());
		messages.setStyleName("logger-messages");
	}
	
	public static void report(String text, String color) {
		Label newLabel = new Label();
		String time = DateTimeFormat.getMediumTimeFormat().format(new Date());
		newLabel.setText(time + " " + text);
		newLabel.getElement().getStyle().setProperty("color", color);
		messages.insert(newLabel, 0);
	}
	
	public static void notice(String text) {
		report(text, "gray");
	}
	
	public static void error(String text) {
		report(text, "red");
	}
	
	public static void warning(String text) {
		report(text, "orange");
	}
	
}
